import sun.applet.Main;

import java.io.*;
import java.sql.Array;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 马拉圈
 * Date: 2023-04-07
 * Time: 19:56
 */
public class Demo {


    public static void main6(String[] args) {
        //写操作的
        try(Writer writer = new FileWriter("HELLO_WORLD/123.txt")) {
            writer.write('0');
            writer.write(new char[]{'1', '2', '3', '4', '5', '6'});
            writer.write("789");
            writer.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }





    public static void main(String[] args) throws FileNotFoundException {
        try(Reader reader = new FileReader("HELLO_WORLD/123.txt")) {
            char ch = (char)reader.read();
            char[] chars = new char[7];
            reader.read(chars);
            System.out.println(ch);
            System.out.println(chars);
            int c = 0;
            do {
                c = reader.read();
                System.out.println((char)c);
            }while (c != -1);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }






    public static void main4(String[] args) {
        //每次打开输出流，都会清空文件内容~
        try(OutputStream outputStream = new FileOutputStream("HELLO_WORLD/123.txt")) {

            outputStream.write(new byte[]{1, 2, 3, 4, 5, 6, 7});

        } catch (IOException e) {
            e.printStackTrace();
        }
    }





    public static void main3(String[] args) {
        try(InputStream inputStream = new FileInputStream("HELLO_WORLD/123.txt")) {
            byte[] bytes = new byte[9];
            System.out.println(inputStream.read(bytes));
            System.out.println(Arrays.toString(bytes));
            String str1 = new String(bytes);
            String str2 = new String(bytes, 0, bytes.length);
            System.out.println(str1);
            System.out.println(str2);


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }




    public static void main2(String[] args) {
        try(InputStream inputStream = new FileInputStream("HELLO_WORLD/123.txt")) {
            int b = 0;
            do {
                b = inputStream.read();
                System.out.println(b);
            }while(b != -1);


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }






    public static void main1(String[] args) throws IOException {
        InputStream inputStream = new FileInputStream("HELLO_WORLD");
        //有了输入流，就相当于你有了“介质”
        //相当于打开文件，文件的信息可以出来



        inputStream.close();
        //关闭输入流
        //相当于关闭文件
        //  如果不关闭，可能会导致，文件资源泄露 ===>
        // 进程里有个文件描述符表，一旦打开文件多了，这个表可能会爆了，导致机器出问题！
        //Java的对象，没用了会自动释放，但是这里的流对象并不会！！！
    }


}
